﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyManageViewControl
{
    public partial class QuestionManageView : ManageView
    {
        public event EventHandler QuestionIdChange;

        public QuestionManageView()
        {
            InitializeComponent();
        }

        public int QuestionId
        {
            get { return int.Parse(tbxQuestionId.Text); }
            set { tbxQuestionId.Text = value.ToString(); }
        }

        public object TopicDataSource
        {
            get { return lbxTopics.DataSource; }
            set { lbxTopics.DataSource = value; }
        }

        public ListBox.SelectedObjectCollection SelectedTopics
        {
            get { return lbxTopics.SelectedItems; }
            set { 
                    foreach(object item in value)
                    {
                        lbxTopics.Items.Add(item);
                    }
                }
        }

        public string TopicDisplayMember
        {
            get { return lbxTopics.DisplayMember; }
            set { lbxTopics.DisplayMember = value; }
        }

        public string QuestionDescription
        {
            get { return tbxQuestionDescription.Text; }
            set { tbxQuestionDescription.Text = value; }
        }

        public string QuestionType
        {
            get { return cbxQuestionType.SelectedItem.ToString().Trim(); }
            set {
                    int index = 1;
                    if (value.ToString().ToUpper().Trim() == "SINGLE")
                    {
                        index = 0;
                    }
                    cbxQuestionDisplayType.SelectedIndex = cbxQuestionType.SelectedIndex = index;

                    ChangeDisplayOption(index);
                }
        }

        public string Option1
        {
            get { return tbxOption1.Text; }
            set { tbxOption1.Text = value; }
        }

        public string Option2
        {
            get { return tbxOption2.Text; }
            set { tbxOption2.Text = value; }
        }

        public string Option3
        {
            get { return tbxOption3.Text; }
            set { tbxOption3.Text = value; }
        }

        public string Option4
        {
            get { return tbxOption4.Text; }
            set { tbxOption4.Text = value; }
        }

        public Boolean SCheck1
        {
            get { return rdbOption1.Checked; }
            set { rdbOption1.Checked = value; }
        }

        public Boolean SCheck2
        {
            get { return rdbOption2.Checked; }
            set { rdbOption2.Checked = value; }
        }

        public Boolean SCheck3
        {
            get { return rdbOption3.Checked; }
            set { rdbOption3.Checked = value; }
        }

        public Boolean SCheck4
        {
            get { return rdbOption4.Checked; }
            set { rdbOption4.Checked = value; }
        }

        public Boolean MCheck1
        {
            get { return cbxOption1.Checked; }
            set { cbxOption1.Checked = value; }
        }

        public Boolean MCheck2
        {
            get { return cbxOption2.Checked; }
            set { cbxOption2.Checked = value; }
        }

        public Boolean MCheck3
        {
            get { return cbxOption3.Checked; }
            set { cbxOption3.Checked = value; }
        }

        public Boolean MCheck4
        {
            get { return cbxOption4.Checked; }
            set { cbxOption4.Checked = value; }
        }

        private void ResetOptions()
        {
            rdbOption1.Checked = true;
            rdbOption2.Checked = false;
            rdbOption3.Checked = false;
            rdbOption4.Checked = false;

            cbxOption1.Checked = false;
            cbxOption2.Checked = false;
            cbxOption3.Checked = false;
            cbxOption4.Checked = false;
        }
        private void tbxQuestionId_DoubleClick(object sender, EventArgs e)
        {
            tbxQuestionId.Text = "Mã Số Tự Động";
            tbxQuestionDescription.Text = "";
            tbxOption1.Text = "";
            tbxOption2.Text = "";
            tbxOption3.Text = "";
            tbxOption4.Text = "";

            ResetOptions();

            if (QuestionIdChange != null)
            {
                QuestionIdChange(sender, e);
            }
        }

        private void cbxQuestionType_SelectedIndexChanged(object sender, EventArgs e)
        {
                
            int index = cbxQuestionDisplayType.SelectedIndex = cbxQuestionType.SelectedIndex;

            ChangeDisplayOption(index);
            
        }

        private void ChangeDisplayOption(int index)
        {
            ResetOptions();

            if (index == 0)
            {
                rdbOption1.Visible = true;
                rdbOption2.Visible = true;
                rdbOption3.Visible = true;
                rdbOption4.Visible = true;

                cbxOption1.Visible = false;
                cbxOption2.Visible = false;
                cbxOption3.Visible = false;
                cbxOption4.Visible = false;
            }
            else
            {
                rdbOption1.Visible = false;
                rdbOption2.Visible = false;
                rdbOption3.Visible = false;
                rdbOption4.Visible = false;

                cbxOption1.Visible = true;
                cbxOption2.Visible = true;
                cbxOption3.Visible = true;
                cbxOption4.Visible = true;
            }
        }

        private void QuestionManageView_Load(object sender, EventArgs e)
        {
            cbxQuestionType.SelectedIndex = cbxQuestionDisplayType.SelectedIndex = 0;
            ChangeDisplayOption(0);
        }
    }
}
